#include "../inc/registerLogin.h"
#include "../inc/bmp.h"
#include "../inc/touch.h"
#include "../inc/my_arithmetic.h"
#include "../inc/dlist.h"
#include "../inc/dir.h"
#include "../inc/my_thread.h"

//while循环登陆注册界面
int while_log_reg_exit(DNode_t*head , char* user_use_sys){
    while(1){
        int select_num;
        //选择登陆注册界面展示
        select_login_register_show();

        //选择注册或者登录或者退出
        select_num = touch_login_register();
        switch (select_num)
        {
            case REGISTER_BUTTON :
                //注册
                register_show();
                //输入注册账号密码
                register_account(head);
                break;
            case LOGIN_BUTTON :
                //登录
                login_show();
                //输入账号密码
                login_account(user_use_sys);
                //登陆成功进入主界面时的界面
                bmp_show("./res/interface/res_login_to_main.bmp",0,0);
                bmp_show_small("./res/interface/logo.bmp",0,0);
                time_prograss_bar();
                return LOGIN_BUTTON;
            case RL_EXIT_BUTTON :
                //退出
                exit_account();
                return RL_EXIT_BUTTON;
        }
    } 
}


//选择登陆注册界面
void select_login_register_show(){
    bmp_show("./res/login/login_background.bmp",0,0);
    bmp_show_small("./res/login/register_icon.bmp",98,165);
    bmp_show_small("./res/login/login_icon.bmp",498,165);
    bmp_show_small("./res/login/reg_log_Exit.bmp", 690, 340);
}

//返回点击注册登录退出标志
int touch_login_register(){
    //选择注册返回REGISTER_BUTTON，选择登陆返回LOGIN_BUTTON，选择退出返回RL_EXIT_BUTTON
    int select_num = 0;
    int x = 0;
    int y = 0;
    while(1){
        //获取按键上的坐标
        touch_wait(&x,&y);
        if(PLACE_REGISTER(x,y)){
            select_num = REGISTER_BUTTON;
            printf("点击了注册\n");
            break;
        }
        if(PLACE_LOGIN(x,y)){
            select_num = LOGIN_BUTTON;
            printf("点击了登录\n");
            break;
        }
        if(PLACE_RL_EXIT(x,y)){
            select_num = RL_EXIT_BUTTON;
            printf("点击了re_log退出\n");
            break;
        }
    }
    return select_num;
}

//------------------------------------------登录------------------------------------------
//显示登陆界面
void login_show(){
    //显示登陆界面
    bmp_show("./res/login/login_background.bmp",0,0);
    //显示键盘
    bmp_show_small("./res/number_button/number_0.bmp",160,340);
    bmp_show_small("./res/number_button/number_1.bmp",80,240);
    bmp_show_small("./res/number_button/number_2.bmp",160,240);
    bmp_show_small("./res/number_button/number_3.bmp",240,240);
    bmp_show_small("./res/number_button/number_4.bmp",80,140);
    bmp_show_small("./res/number_button/number_5.bmp",160,140);
    bmp_show_small("./res/number_button/number_6.bmp",240,140);
    bmp_show_small("./res/number_button/number_7.bmp",80,40);
    bmp_show_small("./res/number_button/number_8.bmp",160,40);
    bmp_show_small("./res/number_button/number_9.bmp",240,40);
    bmp_show_small("./res/number_button/right.bmp",80,340);
    bmp_show_small("./res/number_button/wrong.bmp",240,340);
    //显示登录界面四个字
    bmp_show_small("./res/login/login_show.bmp",595,40);
    //显示账号密码四个字
    bmp_show_small("./res/number_button/account_pic.bmp",320,240);
    bmp_show_small("./res/number_button/password_pic.bmp",320,340);
    //显示账号空白栏
    for (int i = 400; i < 800; i++)
    {
        for (int j = 240; j < 320; j++)
        {
            lcd_p[j][i] = WHITE;
        }  
    }

    //显示密码空白栏
    for (int i = 400; i < 800; i++)
    {
        for (int j = 340; j < 420; j++)
        {
            lcd_p[j][i] = WHITE;
        }  
    }
}

//登陆界面的账号密码点击操作
void login_account(char* user_use_sys){
    int x = 0;
    int y = 0;
    int flag_acc_pd = 0;
    //起始账号栏x坐标
    int realTimeacc_X = 400;
    //起始密码栏x坐标
    int realTimeX = 400;
    //int num = 0;
    //int place = 0;
    //账号缓冲
    char loginScr_acc[MAX_ACCOUNT] = {0};
    //密码缓冲
    char loginScr[MAX_PASSWORD] = {0};
    //创建一条子线程在账号栏目,执行特效
    pthread_t thread_acc;
    pthread_create(&thread_acc,NULL,real_time_bounce_1,NULL);
    //创建一条子线程在密码栏目,执行特效
    pthread_t thread_pas;
    pthread_create(&thread_pas,NULL,real_time_bounce_2,NULL);
    while(1){
        //获取按键上的坐标
        touch_wait(&x,&y);
        //按右边账号栏，密码栏
        if(PLACE_ACCOUNT(x,y)){
            flag_acc_pd = TOUCH_ACCOUNT_COLUMN;
            rtb_should = 1;
            printf("点击了账号栏\n");
        }
        if(PLACE_PASSWORD(x,y)){
            flag_acc_pd = TOUCH_PASSWORD_COLUMN;
            rtb_should = 2;
            printf("点击了密码栏\n");
        }
        //获取的坐标打印到空白栏
        //按左边的键盘
        if(PLACE_0(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                //涂白先
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_0.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"0");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了0,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_0.bmp", realTimeX, 340);
                strcat(loginScr,"0");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了0,密码\n");
            } 
        }
        if(PLACE_1(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_1.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"1");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了1,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_1.bmp", realTimeX, 340);
                strcat(loginScr,"1");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了1,密码\n");
            } 
        }
        if(PLACE_2(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_2.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"2");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了2,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_2.bmp", realTimeX, 340);
                strcat(loginScr,"2");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了2,密码\n");
            } 
        }
        if(PLACE_3(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_3.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"3");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了3,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_3.bmp", realTimeX, 340);
                strcat(loginScr,"3");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了3,密码\n");
            } 
        }
        if(PLACE_4(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_4.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"4");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了4,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_4.bmp", realTimeX, 340);
                strcat(loginScr,"4");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了4,密码\n");
            } 
        }
        if(PLACE_5(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_5.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"5");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了5,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_5.bmp", realTimeX, 340);
                strcat(loginScr,"5");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了5,密码\n");
            } 
        }
        if(PLACE_6(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_6.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"6");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了6,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_6.bmp", realTimeX, 340);
                strcat(loginScr,"6");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了6,密码\n");
            } 
        }
        if(PLACE_7(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_7.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"7");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了7,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_7.bmp", realTimeX, 340);
                strcat(loginScr,"7");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了7,密码\n");
            } 
        }
        if(PLACE_8(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_8.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"8");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了8,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_8.bmp", realTimeX, 340);
                strcat(loginScr,"8");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了8,密码\n");
            } 
        }
        if(PLACE_9(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_9.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"9");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了9,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_9.bmp", realTimeX, 340);
                strcat(loginScr,"9");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了9,密码\n");
            } 
        }
        if(PLACE_RIGNT(x,y)){
            //在文件中找到了一样的账号密码就登陆成功
            int login_suc = dir_login_user("./user_info/users.txt",loginScr_acc,loginScr);
            if(login_suc == 1){
                //登陆成功就进入主界面了
                printf("登陆成功！！\n");
                strcpy(user_use_sys,loginScr_acc);
                //线程都退出
                account_x = 400;
                password_x = 400;
                rtb_should = -1;
                break;
            }else{
                //登陆失败就清屏//清空 ，白屏  以及赋初值
                for (int i = 400; i < 800; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                for (int i = 400; i < 800; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                realTimeacc_X = 400;
                realTimeX = 400;
                account_x = 400;
                password_x = 400;
                //loginScr[20] = {0};
                memset(loginScr_acc, 0, MAX_ACCOUNT); 
                memset(loginScr, 0, MAX_PASSWORD); 
            }
            //if((strcmp(loginScr,PASSWORD)) == 0 && (strcmp(loginScr_acc,ACCOUNT)) == 0){
            //}else{      
            printf("点击了对\n");
        }
        if(PLACE_WRONG(x,y)){
            //删除一个数据，即（页面涂白）
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X >400){
                for (int i = realTimeacc_X - 80; i < realTimeacc_X; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                if(realTimeacc_X <= 720){
                    for (int i = realTimeacc_X; i < realTimeacc_X + 10; i++)
                    {
                        for (int j = 240; j < 320; j++)
                        {
                            lcd_p[j][i] = WHITE;
                        }  
                    }
                }   
                remove_last_char(loginScr_acc);
                realTimeacc_X -= 80;
                account_x = realTimeacc_X;
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX >400){
                for (int i = realTimeX - 80; i < realTimeX; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                if(realTimeX <= 720){
                    for (int i = realTimeX; i < realTimeX + 10; i++)
                    {
                        for (int j = 340; j < 420; j++)
                        {
                            lcd_p[j][i] = WHITE;
                        }  
                    }
                }   
                remove_last_char(loginScr);
                realTimeX -= 80;
                password_x = realTimeX;
            }
            printf("点击了错\n");
        }
    }
}

//------------------------------------------注册------------------------------------------
//显示注册界面
void register_show(){
    //显示注册界面
    bmp_show("./res/login/login_background.bmp",0,0);
    //显示键盘
    bmp_show_small("./res/number_button/number_0.bmp",160,340);
    bmp_show_small("./res/number_button/number_1.bmp",80,240);
    bmp_show_small("./res/number_button/number_2.bmp",160,240);
    bmp_show_small("./res/number_button/number_3.bmp",240,240);
    bmp_show_small("./res/number_button/number_4.bmp",80,140);
    bmp_show_small("./res/number_button/number_5.bmp",160,140);
    bmp_show_small("./res/number_button/number_6.bmp",240,140);
    bmp_show_small("./res/number_button/number_7.bmp",80,40);
    bmp_show_small("./res/number_button/number_8.bmp",160,40);
    bmp_show_small("./res/number_button/number_9.bmp",240,40);
    bmp_show_small("./res/number_button/right.bmp",80,340);
    bmp_show_small("./res/number_button/wrong.bmp",240,340);
    //显示注册界面四个字
    bmp_show_small("./res/login/register_show.bmp",595,40);
    //显示账号密码四个字
    bmp_show_small("./res/number_button/account_pic.bmp",320,240);
    bmp_show_small("./res/number_button/password_pic.bmp",320,340);
    //显示账号空白栏
    for (int i = 400; i < 800; i++)
    {
        for (int j = 240; j < 320; j++)
        {
            lcd_p[j][i] = WHITE;
        }  
    }

    //显示密码空白栏
    for (int i = 400; i < 800; i++)
    {
        for (int j = 340; j < 420; j++)
        {
            lcd_p[j][i] = WHITE;
        }  
    }
    
}

//注册界面的账号密码点击操作
void register_account(DNode_t*head){
    int x = 0;
    int y = 0;
    int flag_acc_pd = 0;
    //起始账号栏x坐标
    int realTimeacc_X = 400;
    //起始密码栏x坐标
    int realTimeX = 400;
    //int num = 0;
    //int place = 0;
    //账号缓冲
    char loginScr_acc[MAX_ACCOUNT] = {0};
    //密码缓冲
    char loginScr[MAX_PASSWORD] = {0};
    //创建一条子线程在账号栏目,执行特效
    pthread_t thread_acc;
    pthread_create(&thread_acc,NULL,real_time_bounce_1,NULL);
    //创建一条子线程在密码栏目,执行特效
    pthread_t thread_pas;
    pthread_create(&thread_pas,NULL,real_time_bounce_2,NULL);
    while(1){
        //获取按键上的坐标
        touch_wait(&x,&y);
        //按右边账号栏，密码栏
        if(PLACE_ACCOUNT(x,y)){
            flag_acc_pd = TOUCH_ACCOUNT_COLUMN;
            rtb_should = 1;
            printf("点击了账号栏\n");
            printf("rtb_should = %d\n",rtb_should);
        }
        if(PLACE_PASSWORD(x,y)){
            flag_acc_pd = TOUCH_PASSWORD_COLUMN;
            rtb_should = 2;
            printf("点击了密码栏\n");
            printf("rtb_should = %d\n",rtb_should);
        }
        //获取的坐标打印到空白栏
        //按左边的键盘
        if(PLACE_0(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                //涂白先
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }  
                bmp_show_small("./res/number_button/number_0.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"0");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了0,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_0.bmp", realTimeX, 340);
                strcat(loginScr,"0");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了0,密码\n");
            } 
        }
        if(PLACE_1(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_1.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"1");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了1,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_1.bmp", realTimeX, 340);
                strcat(loginScr,"1");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了1,密码\n");
            } 
        }
        if(PLACE_2(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_2.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"2");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了2,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_2.bmp", realTimeX, 340);
                strcat(loginScr,"2");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了2,密码\n");
            } 
        }
        if(PLACE_3(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_3.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"3");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了3,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_3.bmp", realTimeX, 340);
                strcat(loginScr,"3");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了3,密码\n");
            } 
        }
        if(PLACE_4(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_4.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"4");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了4,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_4.bmp", realTimeX, 340);
                strcat(loginScr,"4");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了4,密码\n");
            } 
        }
        if(PLACE_5(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_5.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"5");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了5,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_5.bmp", realTimeX, 340);
                strcat(loginScr,"5");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了5,密码\n");
            } 
        }
        if(PLACE_6(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_6.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"6");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了6,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_6.bmp", realTimeX, 340);
                strcat(loginScr,"6");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了6,密码\n");
            } 
        }
        if(PLACE_7(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_7.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"7");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了7,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_7.bmp", realTimeX, 340);
                strcat(loginScr,"7");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了7,密码\n");
            } 
        }
        if(PLACE_8(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_8.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"8");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了8,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_8.bmp", realTimeX, 340);
                strcat(loginScr,"8");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了8,密码\n");
            } 
        }
        if(PLACE_9(x,y)){
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X <= 720){
                for (int i = realTimeacc_X ; i < realTimeacc_X +10; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_9.bmp", realTimeacc_X, 240);
                strcat(loginScr_acc,"9");
                realTimeacc_X += 80;
                account_x = realTimeacc_X;
                printf("点击了9,账号\n");
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX <= 720){
                for (int i = realTimeX; i < realTimeX +10; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                bmp_show_small("./res/number_button/number_9.bmp", realTimeX, 340);
                strcat(loginScr,"9");
                realTimeX += 80;
                password_x = realTimeX;
                printf("点击了9,密码\n");
            } 
        }
        if(PLACE_RIGNT(x,y)){
            //如果账号和密码都有值才判定，这是最基本条件
            printf("点击了对\n");
            if(strlen(loginScr_acc)!=0 && strlen(loginScr)!= 0){
                //判断链表中有没有重复的账号
                int judge_acc = dir_user_exist_list(head,loginScr_acc);
                if(judge_acc == 1){
                    //有重复的就清空
                    //清空 ，白屏  以及赋初值
                    for (int i = 400; i < 800; i++)
                    {
                        for (int j = 240; j < 320; j++)
                        {
                            lcd_p[j][i] = WHITE;
                        }  
                    }
                    for (int i = 400; i < 800; i++)
                    {
                        for (int j = 340; j < 420; j++)
                        {
                            lcd_p[j][i] = WHITE;
                        }  
                    }
                    realTimeacc_X = 400;
                    realTimeX = 400;
                    account_x = 400;
                    password_x = 400;
                    //loginScr[20] = {0};
                    memset(loginScr_acc, 0, MAX_ACCOUNT); 
                    memset(loginScr, 0, MAX_PASSWORD); 
                    printf("有重复账号，注册失败\n");
                }else{
                    //没有重复的就注册成功(添加到文件以及链表中)
                    register_success(head,loginScr_acc,loginScr);
                    //注册成功在user_info里创建一个用户专用的文件夹
                    //先拼接路径
                    char path_re_su[25];
                    sprintf(path_re_su,"./user_info/user%s",loginScr_acc);
                    mkdir(path_re_su, 0777);
                    printf("注册成功！！\n");
                    //线程都退出
                    rtb_should = -1;
                    account_x = 400;
                    password_x = 400;
                    //成功就跳转到注册登陆界面
                    break;
                }
            }else{
                //清空 ，白屏  以及赋初值
                for (int i = 400; i < 800; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                for (int i = 400; i < 800; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                realTimeacc_X = 400;
                realTimeX = 400;
                account_x = 400;
                password_x = 400;
                //loginScr[20] = {0};
                memset(loginScr_acc, 0, MAX_ACCOUNT); 
                memset(loginScr, 0, MAX_PASSWORD);
                printf("账号或密码未输入完整\n");
            }
            // if((strcmp(loginScr,PASSWORD)) == 0 && (strcmp(loginScr_acc,ACCOUNT)) == 0){
            //     printf("登陆成功！！\n");
            //     break;
            //}
            // else{
            //     //清空 ，白屏  以及赋初值
            //     for (int i = 400; i < 800; i++)
            //     {
            //         for (int j = 240; j < 320; j++)
            //         {
            //             lcd_p[j][i] = WHITE;
            //         }  
            //     }
            //     for (int i = 400; i < 800; i++)
            //     {
            //         for (int j = 340; j < 420; j++)
            //         {
            //             lcd_p[j][i] = WHITE;
            //         }  
            //     }
            //     realTimeacc_X = 400;
            //     realTimeX = 400;
            //     //loginScr[20] = {0};
            //     memset(loginScr_acc, 0, MAX_ACCOUNT); 
            //     memset(loginScr, 0, MAX_PASSWORD); 
            // }
        }
        if(PLACE_WRONG(x,y)){
            //删除一个数据，即（页面涂白）
            if(flag_acc_pd == TOUCH_ACCOUNT_COLUMN && realTimeacc_X >400){
                for (int i = realTimeacc_X - 80; i < realTimeacc_X; i++)
                {
                    for (int j = 240; j < 320; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                if(realTimeacc_X <= 720){
                    for (int i = realTimeacc_X; i < realTimeacc_X + 10; i++)
                    {
                        for (int j = 240; j < 320; j++)
                        {
                            lcd_p[j][i] = WHITE;
                        }  
                    }
                }   
                remove_last_char(loginScr_acc);
                realTimeacc_X -= 80;
                account_x = realTimeacc_X;
                
            }
            if(flag_acc_pd == TOUCH_PASSWORD_COLUMN && realTimeX >400){
                for (int i = realTimeX - 80; i < realTimeX; i++)
                {
                    for (int j = 340; j < 420; j++)
                    {
                        lcd_p[j][i] = WHITE;
                    }  
                }
                if(realTimeX <= 720){
                    for (int i = realTimeX; i < realTimeX + 10; i++)
                    {
                        for (int j = 340; j < 420; j++)
                        {
                            lcd_p[j][i] = WHITE;
                        }  
                    }
                }   
                remove_last_char(loginScr);
                realTimeX -= 80;
                password_x = realTimeX;
            }
            printf("点击了错\n");
        }
    }
}

//注册时成功就添加到文件中以及链表中
void register_success(DNode_t*head ,char* loginScr_acc ,char* loginScr){
    FILE *fp = fopen("./user_info/users.txt","a");
    if(fp == NULL)
    {
        perror("fopen");
        return ;
    }
    ACCOUNT_PASSWORD_t data;
    strcpy(data.account_pri,loginScr_acc);
    strcpy(data.password_pri,loginScr);
    //写入链表
    list_insert_tail(head ,data);
    //添加到文件中
    //先找到空出的第一行

    //将指定格式的数据写入到文件中 fprintf
    fprintf(fp,"%s %s\n",loginScr_acc,loginScr);

    fclose(fp);
}

//------------------------------------------退出------------------------------------------
//显示点击退出后的界面
void exit_account(){
    //显示退出背景界面
    bmp_show("./res/login/exit_background.bmp",0,0);
    //显示thanks图片
    bmp_show_small("./res/login/thanks.bmp",25,145);

}
